# coding:utf-8
import threading

lock  = threading.Lock()

amount = 0

def changeValue(x):
    global amount
    amount = amount + x
    amount = amount - x
# 批量运行改值
def batchRunThread(x):
    for i in range(1000000):
        lock.acquire() #获得锁
        try:
            changeValue(x)
        finally:
            lock.release() #释放锁
            
# 创建2个线程
t1 = threading.Thread(target=batchRunThread, args=(5,), name = 'Thread1')
t2 = threading.Thread(target=batchRunThread, args=(15,), name = 'Thread2')
t1.start()
t2.start()
t1.join()
t2.join()
print(amount)